module.exports = (sequelize, DataTypes) => {
  const Course = sequelize.define('Course', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
      comment: '课程名称'
    },
    code: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '课程代码'
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: '课程描述'
    },
    category: {
      type: DataTypes.STRING(50),
      allowNull: true,
      comment: '课程类别'
    },
    credit: {
      type: DataTypes.FLOAT,
      allowNull: true,
      comment: '学分'
    },
    totalHours: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: '总课时'
    },
    semester: {
      type: DataTypes.STRING(20),
      allowNull: true,
      comment: '学期'
    }
  }, {
    tableName: 'courses',
    timestamps: true
  });

  Course.associate = (models) => {
    // 课程与知识点的一对多关系
    Course.hasMany(models.KnowledgePoint, {
      foreignKey: 'courseId',
      as: 'knowledgePoints'
    });
  };

  return Course;
};